﻿using AutoMapper;
using QuanLyGiaoVuDAL.DTO;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace QuanLyGiaoVuUI.Models.LopMonHoc
{
    public class LopMonHocViewModel
    {
        public System.Guid LopMonHocId { get; set; }

        [Display(Name = "Mã lớp")]
        public String MaLopMonHoc { get; set; }

        public String MaLopDayDu
        {
            get
            {
                try
                {
                    return MonHoc.MaMonHoc.Trim() + "." + MaLopMonHoc;
                }
                catch
                {
                    return String.Empty;
                }
            }
        }

        public System.Guid MaMonHoc { get; set; }

        [Display(Name = "Mã GV 1")]
        public System.Guid MaGiangVien1 { get; set; }

        [Display(Name = "Mã GV 2")]
        public System.Guid? MaGiangVien2 { get; set; }

        public System.Guid MaHocKy { get; set; }

        public System.Guid MaCa { get; set; }

        public short Thu { get; set; }

        public System.Nullable<System.Guid> MaPhong { get; set; }

        [Display(Name = "Sĩ số tối đa")]
        public int SiSoToiDa { get; set; }

        [Display(Name = "Sĩ số")]
        public int SiSoThucTe { get; set; }

        [Display(Name = "Loại Lớp")]
        public int LoaiLop { get; set; }

        public short TyLeDiem { get; set; }

        public System.Guid MaLopChinh { get; set; }

        [Display(Name = "Lớp sinh viên")]
        public Guid? LopSinhVienId { get; set; }

        [Display(Name = "Xác nhận")]
        public bool GiangVienXacNhan { get; set; }

        [Display(Name="Đã phản hồi")]
        public bool DaPhanHoi { get; set; }

        [Display(Name = "Ghi chú")]
        public String GhiChu { get; set; }

        public TietHocDTO TietDau { get; set; }

        public TietHocDTO TietSau { get; set; }

        public String Phong { get; set; }

        public String TietDayString
        {
            get
            {
                string result = string.Empty;
                try
                {
                    int tietDau = TietDau.TietThu;
                    int tietSau = TietSau.TietThu;
                    for (int tiet = tietDau; tiet <= tietSau; tiet++)
                        result += tiet.ToString();
                    return result;
                }
                catch (Exception exception)
                {
                    return string.Empty;
                }
            }
        }

        public MonHocDTO MonHoc { get; set; }

        public GiangVienDTO GiangVien1 { get; set; }

        public GiangVienDTO GiangVien2 { get; set; }

        public HocKyDTO HocKy { get; set; }

        //public CaDTO Ca { get; set; }

        public LopSinhVienDTO LopSinhVien { get; set; }

        public LichThiDTO LichThi { get; set; }

        public List<LichThiDTO> DanhSachLichThi { get; set; }

        public String MaLopVaTenMonHoc
        {
            get
            {
                return MonHoc.MaMonHoc.Trim() + "." + MaLopMonHoc + " - " + MonHoc.TenMonHoc;
            }
        }

        public LopMonHocDTO ToLopMonHocDTO()
        {
            Mapper.CreateMap(typeof(LopMonHocViewModel), typeof(LopMonHocDTO));
            var lopMonHocDTO = new LopMonHocDTO();
            Mapper.Map(this, lopMonHocDTO);
            return lopMonHocDTO;
        }

        public static LopMonHocViewModel FromLopMonHocDTO(LopMonHocDTO lopMonHocDTO)
        {
            Mapper.CreateMap(typeof(LopMonHocDTO), typeof(LopMonHocViewModel));
            var lopMonHocViewModel = new LopMonHocViewModel();
            Mapper.Map(lopMonHocDTO, lopMonHocViewModel);
            return lopMonHocViewModel;
        }

        public static IEnumerable<LopMonHocViewModel> FromLopMonHocDTOList(IEnumerable<LopMonHocDTO> lopMonHocDTOList)
        {
            List<LopMonHocViewModel> lopMonHocList = new List<LopMonHocViewModel>();
            foreach (LopMonHocDTO lopMonHocDTO in lopMonHocDTOList)
            {
                lopMonHocList.Add(LopMonHocViewModel.FromLopMonHocDTO(lopMonHocDTO));
            }
            return lopMonHocList.AsEnumerable();
        }
    }
}